package com.dysm.spring.security.exception;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 使用了全局异常处理时，未登录直接访问授权页面时会返回服务器内部错误，而不能自动
 * 重定向到登录页面，故此处不能加全局异常处理
 */
@RestControllerAdvice
public class GlobalExceptionHandle {
    private final Logger LOG = LoggerFactory.getLogger(this.getClass());

//    @ExceptionHandler(Exception.class)
//    public ResponseEntity<Map<String, String>> undefinedException(HttpServletRequest request, Exception e) {
//        LOG.error("request:[{}],请求异常：", request.getRequestURI(), e);
//        Map<String, String> returnMap = new HashMap<>();
//        returnMap.put("code", "99999");
//        returnMap.put("msg", "服务器内部错误");
//        return ResponseEntity.ok(returnMap);
//    }
}
